class EXAMPLE9
-- Using an IUP_COLOR_BAR an IUP_CELLS and an IUP_CANVAS.

inherit
	IUP_INTERFACE

create {ANY}
   make

feature {ANY}

	cb: IUP_COLOR_BAR
	
   make
      local
 			gui: IUP
			i: STRING
			lab: IUP_LABEL
			a: ARRAY[IUP_CANVAS]
			b: ARRAY[IUP_WIDGET]
			a_cells: IUP_CELLS
			h: IUP_HBOX
			v: IUP_VBOX
			w: IUP_DIALOG

      do
			gui := iup_open
			gui.load_iup_controls

			create cb.color_bar
			
			cb.set_raster_size(70, 0)
			cb.set_number_of_parts(2)
			cb.expand_vertical
			cb.set_cb_select(agent select_color)

			create lab.label("Select a color and click a cell")
			create a_cells.cells

			a_cells.set_scrollbar(False)
			a_cells.set_cb_number_of_lines(agent lines)
			a_cells.set_cb_number_of_columns(agent columns)
			a_cells.set_cb_height(agent height)
			a_cells.set_cb_width(agent width)
			a_cells.set_cb_draw(agent draw)
			a_cells.set_cb_scroll(agent scroll)
			a_cells.set_cb_mouse_click(agent mouse_click)

			a := {ARRAY[IUP_CANVAS]} << a_cells, cb >>
			create h.hbox(a)

			b := {ARRAY[IUP_WIDGET]} << lab, h >>
			create v.vbox(b)
			
	      create w.dialog(v)
			w.set_title("An example of IUP_CELLS")
			w.set_raster_size(400, 350)
			w.set_resize(False)
	      i := w.show

         gui.main_loop
			gui.close
      end

	select_color (widget: IUP_COLOR_BAR; cell, type: INTEGER): STRING
		do
			Result := "IUP_DEFAULT"
		end

	lines (widget: IUP_CELLS): INTEGER
		do
			Result := 10
		end

	columns (widget: IUP_CELLS): INTEGER
		do
			Result := 10
		end

	height (widget: IUP_CELLS; l: INTEGER): INTEGER
		do
			Result := 30
		end

	width (widget: IUP_CELLS; c: INTEGER): INTEGER
		do
			Result := 30
		end

	draw (widget: IUP_CELLS; l, c, xmin, xmax, ymin, ymax: INTEGER; cd: CD_IUP): STRING
		local
			mx, my: INTEGER
		do
			cd.set_predefined_background_color(cd.cd_black)

			mx := xmin + 15
			my := ymin + 15
			cd.draws_mark(mx, my)

			Result := "IUP_DEFAULT"
		end

	scroll (widget: IUP_CANVAS; op: INTEGER; posx, posy: REAL_32): STRING
		do
			Result := "IUP_IGNORE"
		end

	mouse_click (widget: IUP_CELLS; b, p, l, c, x, y: INTEGER; s: STRING): STRING
		local
			i: INTEGER
			tup: TUPLE[INTEGER, INTEGER, INTEGER]
		do
			-- If user press the left mouse button, draw a mark with
			-- the selected color.
			-- io.put_natural_32(b)
			if b.is_equal(1) and p.is_equal(1) then
				i := cb.get_primary_cell
				tup := cb.get_cell_n_color(i)

				widget.get_cd_canvas.set_foreground_color(tup.integer_32_item(1), tup.integer_32_item(2), tup.integer_32_item(3))
				widget.get_cd_canvas.draws_mark(30*(c - 1) + 15, (10 - l)*30 + 21)
				widget.get_cd_canvas.flush
			end
			
			Result := "IUP_CONTINUE"
		end

end -- class EXAMPLE9
